//
//  LCShengJingTextViewController+LCSettingUI.m
//  JKFuYinProject
//
//  Created by admin on 2018/1/8.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LCShengJingTextViewController+LCSettingUI.h"
#import "LCShengJingTextViewController+LoadData.h"

@implementation LCShengJingTextViewController (LCSettingUI)

- (void)setupHeaderSettingBtn{
    //    右设置
    UIView * rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    
    UIView * settingView = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 30, 30)];
    UIImageView * settingImageV = [[UIImageView alloc] initWithFrame:CGRectMake(9, 3, 21, 20)];
    settingImageV.userInteractionEnabled = YES;
    settingImageV.image = [UIImage imageNamed:@"header_set"];
    [settingView addSubview:settingImageV];
    [rightView addSubview:settingView];
    @weakify(self)
    [settingView tapGesture:^(UIGestureRecognizer *ges) {
        @strongify(self)
        [self settingTap];
    }];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightView];
}
#pragma mark - 设置
- (void)settingTap {
    if (self.settingView.hidden) {
        [self animationHiddenManagerShengJingView];
        //        [self.managerShengJingDic removeAllObjects];
        self.fuzhiStr = @"";
        self.settingView.hidden = NO;
        self.setLiangSlider.value = [UIScreen mainScreen].brightness;//获取当前屏幕的亮度
        [self.view bringSubviewToFront:self.settingView];
    }else{
        self.settingView.hidden = YES;
    }
}
//51.181.229
//圣经章节管理界面(新设计需求)
- (void)setupSettingUI {
    NSArray * allArr = [NSArray arrayWithObjects:@"复制", @"分享", @"笔记", @"评论", @"取消", nil];
    self.managerShengJingView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height+60+HOME_INDICATOR_HEIGHT, self.view.width, 60)];
    [[[UIApplication sharedApplication].delegate window] addSubview:self.managerShengJingView];
    
    for (int i = 0; i < allArr.count; i++) {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(i*self.managerShengJingView.width/5, 0, self.managerShengJingView.width/5, self.managerShengJingView.height)];
        [self.managerShengJingView addSubview:view];
        
        view.backgroundColor = [UIColor whiteColor];
        
        UIImageView * tempImage = [[UIImageView alloc] initWithFrame:CGRectMake((view.width-27)/2, 8, 27, 27)];
        tempImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"z%d", i+1]];
        tempImage.userInteractionEnabled = YES;
        [view addSubview:tempImage];
        
        UILabel * tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, tempImage.bottom, view.width, 20)];
        tempLabel.textAlignment = NSTextAlignmentCenter;
        tempLabel.text = [allArr objectAtIndex:i];
        tempLabel.font = FONT_13;
        [view addSubview:tempLabel];
        
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, view.width, view.height);
        btn.userInteractionEnabled = YES;
        btn.backgroundColor = [UIColor clearColor];
        btn.tag = 505+i;
        //        [btn setTitle:[allArr objectAtIndex:i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(managerBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [btn addTarget:self action:@selector(managerBtnColor1:) forControlEvents:UIControlEventTouchDown];
        [btn addTarget:self action:@selector(managerBtnColor:) forControlEvents:UIControlEventTouchUpOutside];
        [view addSubview:btn];
        
        
        
        
    }
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.managerShengJingView.width, 2)];
    lineView.backgroundColor = [UIColor colorWithRed:255/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    [self.managerShengJingView addSubview:lineView];
    
    
    ///MARK:- 圣经设置界面
    self.settingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 150)];
    self.settingView.backgroundColor = [JK_HUISE_LINE_COLOR colorWithAlphaComponent:0.95];
    UIView * fontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.settingView.width, self.settingView.height/3)];
    UILabel * fontLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, fontView.height)];
    fontLabel.text = @"字体";
    fontLabel.textAlignment = NSTextAlignmentCenter;
    fontLabel.font = FONT_14;
    [fontView addSubview:fontLabel];
    //字体加
    UIButton * fontJianBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fontJianBtn.frame = CGRectMake(fontLabel.right, (fontView.height-25)/2, 100, 25);
    [fontJianBtn setBackgroundImage:[UIImage imageNamed:@"zitixiao"] forState:UIControlStateNormal];
    [fontJianBtn addTarget:self action:@selector(fontJian) forControlEvents:UIControlEventTouchUpInside];
    [fontView addSubview:fontJianBtn];
    //字体减
    UIButton * fontJiaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fontJiaBtn.frame = CGRectMake(fontView.width-130, (fontView.height-25)/2, 100, 25);
    [fontJiaBtn setBackgroundImage:[UIImage imageNamed:@"zitida"] forState:UIControlStateNormal];
    [fontJiaBtn addTarget:self action:@selector(fontJia) forControlEvents:UIControlEventTouchUpInside];
    [fontView addSubview:fontJiaBtn];
    UIView * lineFont = [[UIView alloc] initWithFrame:CGRectMake(0, fontView.height-1, fontView.width, 1)];
    lineFont.backgroundColor = JK_HUISE_COLOR;
    [fontView addSubview:lineFont];
    [self.settingView addSubview:fontView];
    
    
    
    //亮度
    UIView * liangduView = [[UIView alloc] initWithFrame:CGRectMake(0, self.settingView.height/3, self.settingView.width, self.settingView.height/3)];
    UILabel * liangduLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, liangduView.height)];
    liangduLabel.text = @"亮度";
    liangduLabel.textAlignment = NSTextAlignmentCenter;
    liangduLabel.font = FONT_14;
    [liangduView addSubview:liangduLabel];
    self.setLiangSlider = [[UISlider alloc] initWithFrame:CGRectMake(liangduLabel.right, (liangduView.height-30)/2, liangduView.width-liangduLabel.right-30, 30)];
    self.setLiangSlider.value = [UIScreen mainScreen].brightness;
    self.setLiangSlider.minimumTrackTintColor = JK_RED_COLOR;
    [self.setLiangSlider addTarget:self action:@selector(changePhoneLiangdu:) forControlEvents:UIControlEventValueChanged];
    [liangduView addSubview:self.setLiangSlider];
    UIView * lineLiangdu = [[UIView alloc] initWithFrame:CGRectMake(0, liangduView.height-1, liangduView.width, 1)];
    lineLiangdu.backgroundColor = JK_HUISE_COLOR;
    [liangduView addSubview:lineLiangdu];
    [self.settingView addSubview:liangduView];
    
    
    //背景
    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.settingView.height/3*2, self.settingView.width, self.settingView.height/3)];
    UILabel * bgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, bgView.height)];
    bgLabel.text = @"背景";
    bgLabel.textAlignment = NSTextAlignmentCenter;
    bgLabel.font = FONT_14;
    [bgView addSubview:bgLabel];
    
    UIButton * bgWhiteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgWhiteBtn.frame = CGRectMake(bgLabel.right, (bgView.height-30)/2, 30, 30);
    bgWhiteBtn.tag = 1401;
    [bgWhiteBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn1"] forState:UIControlStateNormal];
    [bgWhiteBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgWhiteBtn];
    
    UIButton * bgBlueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgBlueBtn.frame = CGRectMake(bgView.width-30-30, (bgView.height-30)/2, 30, 30);
    bgBlueBtn.tag = 1404;
    [bgBlueBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn4"] forState:UIControlStateNormal];
    [bgBlueBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgBlueBtn];
    
    
    UIButton * bgRedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgRedBtn.frame = CGRectMake((bgBlueBtn.left-bgWhiteBtn.right-2*30)/3+bgWhiteBtn.right, (bgView.height-30)/2, 30, 30);
    bgRedBtn.tag = 1402;
    [bgRedBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn2"] forState:UIControlStateNormal];
    [bgRedBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgRedBtn];
    
    UIButton * bgGreenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgGreenBtn.frame = CGRectMake((bgBlueBtn.left-bgWhiteBtn.right-2*30)/3+bgRedBtn.right, (bgView.height-30)/2, 30, 30);
    bgGreenBtn.tag = 1403;
    [bgGreenBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn3"] forState:UIControlStateNormal];
    [bgGreenBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgGreenBtn];
    
    UIView * lineBg = [[UIView alloc] initWithFrame:CGRectMake(0, bgView.height-1, bgView.width, 1)];
    lineBg.backgroundColor = JK_HUISE_COLOR;
    [bgView addSubview:lineBg];
    [self.settingView addSubview:bgView];
    
    NSLog(@"%zd", [TheHomeManager shareTheHomeManager].btnTempTag);
    
    
    if ([TheHomeManager shareTheHomeManager].btnTempTag == 0) {
        [TheHomeManager shareTheHomeManager].btnTempTag = 1401;
        [bgWhiteBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn01"] forState:UIControlStateNormal];
        self.view.backgroundColor = [UIColor whiteColor];
    }else{
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1401) {
            [bgWhiteBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn01"] forState:UIControlStateNormal];
            self.view.backgroundColor = [UIColor whiteColor];
        }
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1402) {
            [bgRedBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn02"] forState:UIControlStateNormal];
            self.view.backgroundColor = JK_FENRED_COLOR;
            
        }
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1403) {
            [bgGreenBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn03"] forState:UIControlStateNormal];
            self.view.backgroundColor = JK_GREEN_COLOR;
            
        }
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1404) {
            [bgBlueBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn04"] forState:UIControlStateNormal];
            self.view.backgroundColor = JK_BLUE_COLOR;
            
        }
        
    }
    
    [self.view addSubview:self.settingView];
    self.settingView.hidden = YES;
}
- (void)changeBgColor:(UIButton *)btn
{
    UIButton * oldBtn = (UIButton *)[self.view viewWithTag:[TheHomeManager shareTheHomeManager].btnTempTag];
    if (oldBtn.tag == 1401) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn1"] forState:UIControlStateNormal];
    }
    if (oldBtn.tag == 1402) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn2"] forState:UIControlStateNormal];
    }
    if (oldBtn.tag == 1403) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn3"] forState:UIControlStateNormal];
    }
    if (oldBtn.tag == 1404) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn4"] forState:UIControlStateNormal];
    }
    
    
    if (btn.tag == 1401) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn01"] forState:UIControlStateNormal];
        self.view.backgroundColor = [UIColor whiteColor];
        self.bibleTableViewController.view.backgroundColor = [UIColor whiteColor];
    }
    if (btn.tag == 1402) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn02"] forState:UIControlStateNormal];
        self.view.backgroundColor = JK_FENRED_COLOR;
        self.bibleTableViewController.view.backgroundColor = JK_FENRED_COLOR;
    }
    if (btn.tag == 1403) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn03"] forState:UIControlStateNormal];
        self.view.backgroundColor = JK_GREEN_COLOR;
        self.bibleTableViewController.view.backgroundColor = JK_GREEN_COLOR;
    }
    if (btn.tag == 1404) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn04"] forState:UIControlStateNormal];
        self.view.backgroundColor = JK_BLUE_COLOR;
        self.bibleTableViewController.view.backgroundColor = JK_BLUE_COLOR;
    }
    
    [TheHomeManager shareTheHomeManager].btnTempTag = btn.tag;
}
//字体加减
- (void)fontJia{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BIBLETEXTFONT" object:self userInfo:@{@"BIBLETEXTFONT":@(+1)}];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"BIBLETEXTFONT" object:nil];
}
//字体减
- (void)fontJian{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BIBLETEXTFONT" object:self userInfo:@{@"BIBLETEXTFONT":@(-1)}];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"BIBLETEXTFONT" object:nil];
}
/// 亮度与背景设置
- (void)changePhoneLiangdu:(UISlider *)slider{
    [[UIScreen mainScreen] setBrightness:slider.value];//设置窗口亮度大小 范围是0.1 -1.0
}
//MARK:-

#pragma mark - 圣经管理(复制, 分享, 笔记, 收藏, 高亮)
- (void)managerBtnAction:(UIButton *)btn
{
    
    UIView * view = btn.superview;
    view.backgroundColor = [UIColor whiteColor];
    //拼接好需要分享复制收藏的字符串
    NSString *string = [self.bibleTableViewController.selectedData componentsJoinedByString:@"\n"];
    
    if (btn.tag == 505) {       //复制到剪贴板
        NSLog(@"%@", self.fuzhiStr);
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        NSLog(@"%@", string);
        
        NSArray *array = @[_LCPlayer.playingSong.title,@"\n",string];
        NSString *pasteboardString = [array componentsJoinedByString:@""];
        pasteboard.string = pasteboardString;
        [LCUtils showHud2:@"复制成功"];
    }
    
    
    if (btn.tag == 506) {       //分享
        NSLog(@"进行分享");
        //        LCBibleCardController *bibleCardController = [[LCBibleCardController alloc] init];
        //        bibleCardController.shengJingTitle = _LCPlayer.playingSong.title;
        //        bibleCardController.notesContentStr = string;
        DDGScollViewShot *viewController = [[DDGScollViewShot alloc] init];
        viewController.shengJingTitle = _LCPlayer.playingSong.title;
        viewController.notesContentStr = string;
        viewController.selectedData = self.bibleTableViewController.selectedData;
        [self.navigationController pushViewController:viewController animated:YES];
        //        [self.navigationController pushViewController:bibleCardController animated:YES];
        //        NSArray* imageArray = @[[UIImage imageNamed:@"placeholder"]];
        //
        //        [self shareShengJingMessageWithImageArray:imageArray url:_LCPlayer.playingSong.fileUrl title:_LCPlayer.playingSong.title contentMessage:[NSString stringWithFormat:@"%@\n%@",_LCPlayer.playingSong.title,string] type:SSDKContentTypeText];
    }
    
    if (btn.tag == 507) {       //笔记
        if ([[_UserM usercode] isEqualToString:@""]) {
            pushAccLoginVC
        }else{
            ManagerMyNotesViewController *nagerMyNotesViewController = [[ManagerMyNotesViewController alloc] init];
            nagerMyNotesViewController.shengJingTitle = _LCPlayer.playingSong.title;
            nagerMyNotesViewController.notesContentStr = string;
            [self.navigationController pushViewController:nagerMyNotesViewController animated:YES];
        }
        NSLog(@"做笔记");
    }
    
    if (btn.tag == 508) {       //评论
        if (self.bibleTableViewController.selectedData.count > 1) {
            [SVProgressHUD showErrorWithStatus:@"评论最多只能选择1节"];
            return;
        }
        //调用圣经感悟接口
        [self shengJingMessageCollectionWithTitle:_LCPlayer.playingSong.title fuzhiStr:string];
    }
    
    
    if (btn.tag == 509) {       //取消高亮
        NSLog(@"取消高亮");
    }
    if (btn.tag >= 505 && btn.tag <= 509) {
        [self.bibleTableViewController.indexPathArr removeAllObjects];
        [self.bibleTableViewController.selectedData removeAllObjects];
    }
    
    [self animationHiddenManagerShengJingView];
    //    [self.managerShengJingDic removeAllObjects];
    [self.bibleTableViewController.tableView reloadData];
    self.fuzhiStr = @"";
}


- (void)managerBtnColor:(UIButton *)btn
{
    UIView * view = btn.superview;
    view.backgroundColor = [UIColor whiteColor];
}

- (void)managerBtnColor1:(UIButton *)btn
{
    UIView * view = btn.superview;
    view.backgroundColor = JK_FENRED_COLOR;
}

@end
